home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Univers Interactif 3
/
INTERACTIF.BIN
/
mac
/
Planete.net
/
Internet Confirmés_Vrac
/
NetAgent.sea
/
src
/
agentc.c
next >
Wrap
C/C++ Source or Header
|
1992-06-15
|
4KB
|
155 lines
/*
This is an unsupported product. It was developed as part of a study at Ostfold
Regional College, Norway in the spring of 1992.
You use this software at your own risk. Neither the authors nor the Ostfold
Regional College nor any other person or organization except yourself is
responsible for any damage or loss of data derived from the use of this
software. You may distribute this software freely as long as it is in its
original form and all of its files are included. If you make any changes to any
part of this software or the files distributed with it, please state so and do
NOT distribute it under its original name.
*/
/*
This is the main part of the agentc program.
It sets the time between each poll to the NNTP-server and checks for new
news.
*/
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <time.h>
#include <fcntl.h>
#include "nntp_tcp.h"
#include "subjects.h"
#include "filelock.h"
/*
-----------------------------------------------------------------------------
Function name: sett_dato()
-----------------------------------------------------------------------------
Parameters: char *s Pointer to a string containing the time used
in the command to the NNTP-server.
long neste Contains the time elapsed since Jan. 1, 1970
in seconds upto the last poll.
Return value: This function returns the time in seconds, since Jan. 1 1970,
at the point of returning.
Called by: main()
Calls: none
Description: This function runs in a loop until the machine clock has
reach the value cointained in the variable neste.
-----------------------------------------------------------------------------
*/
time_t sett_dato(s, neste)
char *s;
long neste;
{
time_t clock = 0;
struct tm *timeptr;
do{
time(&clock);
}while(clock < neste );
timeptr = localtime(&clock);
strftime(s, 19, "%y%m%d %H%M%S", timeptr);
return(clock);
}
/*
-----------------------------------------------------------------------------
Function name: hent_nye_innlegg()
-----------------------------------------------------------------------------
Parameters: int s A valid socket descriptor.
char *d String pointer to a string containing the
time and date of the last poll to the NNTP-
server.
Return value: none
Called by: main
Calls: lock_file(), unlock_file(), tcp_send(), get_list()
Description: This function call the NNTP-server askeing for the news which
has arrived since the time contained in d. It writes the id
of the articles to the New.News file.
-----------------------------------------------------------------------------
*/
void hent_nye_innlegg(s, d)
int s;
char *d;
{
char command[80];
char buf[BUFSIZ+1];
int f;
f = open("New.News", O_WRONLY|O_TRUNC|O_CREAT, S_IREAD|S_IWRITE);
lock_file(f);
sprintf(command, "newnews * %s\r\n", d);
tcp_send(s, command);
get_list(s, f, 3600);
unlock_file(f);
close(f);
}
/*
-----------------------------------------------------------------------------
Function name: main()
-----------------------------------------------------------------------------
Parameters: int argc Number of arguments.
char *argv[] List of arguments.
Return value: none
Called by: none
Calls: sett_dato(), tcp_connect(), get_msg(), hent_ny_innlegg(),
do_innlegg()
Description: This function runs in an infinitve loop checking for new
news. It does this by calling other functions.
-----------------------------------------------------------------------------
*/
main( argc, argv)
int argc;
char *argv[];
{
int s;
char command[80];
char *host;
char ny_dato[20];
char gammel_dato[20];
char *poll;
long neste;
time_t forrige;
char buf[BUFSIZ+1];
myname = argv[0];
if(argc != 3) {
fprintf(stderr, "Usage: %s host poll\n", myname);
exit(1);
}
host = argv[1];
poll = argv[2];
neste = atol(poll);
forrige = sett_dato(gammel_dato, forrige);
while(1) {
forrige = sett_dato(ny_dato, forrige + neste);
s = tcp_connect(host, "nntp");
if(get_msg(s, '2', LINEFEED, buf, 3600) > 0) {
hent_nye_innlegg(s, gammel_dato);
do_innlegg(s);
strcpy(gammel_dato, ny_dato);
}
close(s);
}
}